package com.hsp_java.map_;

import java.util.*;


@SuppressWarnings({"all"})
public class MapFor_ {
    public static void main(String[] args) {
         Map map = new HashMap();

         map.put("lfm01", 01);
        map.put("lfm02", 02);
        map.put("lfm03", 03);
        map.put("lfm04", 04);


        //iterator
        Set ketSet = map.keySet();
        Iterator iterator = ketSet.iterator();

        while (iterator.hasNext()) {
            Object key = iterator.next();
            System.out.println(key + "-" + map.get(key));
        }

        //for
        for (Object key : ketSet) {
            System.out.println(key + "-" + map.get(key));
        }


        Collection keyValue = map.values();
        //
        for (Object col : keyValue) {
            System.out.println(col + "-" + map.get(col));

        }
        Iterator iterator_value = keyValue.iterator();
        while (iterator_value.hasNext()) {
            Object value = iterator_value.next();
            System.out.println(value);
        }

        //3.通过EntrySet 来获取 k-v
        System.out.println("---------使用EntrySet的for来获取k-v----------");
        Set enrtySet = map.entrySet();

        for (Object s : enrtySet) {
            //将entry 转成 Map.Entry
            Map.Entry m = (Map.Entry)s;
            System.out.println(m.getKey() + "-"  + m.getValue());

        }


        System.out.println("---------使用EntrySet的迭代器来获取k-v----------");

        Iterator entry = enrtySet.iterator();
        while (entry.hasNext()) {
            Object next = entry.next();
            Map.Entry m = (Map.Entry)next;
            System.out.println(m.getKey() + "-" + m.getValue());
        }

        

    }
}
